﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    //
    public class YGREKDOCData : BaseFunction
    {

        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }
        SETINTEXDB INTEXDB = new SETINTEXDB();
        public YGREKDOCData()
            : base()
        {

        }  
        public DataSet LoadEnv()
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            try
            {
            DataRow dwData = INTEXDB.LIEFDAT.NewLIEFDATRow();
            dwData["LSMANDANT"] = "00";
            SResult = INTEXDBC.QueryLIEFDAT(dwData, 6);
            SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet GetOrderBySupplier(DataRow dwInput)
        {
            
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            try
            {
            DataRow dwData = INTEXDB.EKKOPF.NewRow();
            dwData["EKKMANDANT"] = "00";
            dwData["EKKLIEFNR"] =dwInput["LSLIEFNR"].ToString();
            SResult = INTEXDBC.QueryEKKOPF(dwData, 2);
            SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public SETINTEXDB BuildData(string client, string KRS, string LFD)
        {
            SETINTEXDB SReturn = new SETINTEXDB();
            DataSet SResult = new DataSet();
            try
            { 
                SResult = INTEXBL.QueryEKK(MANDANT, KRS, LFD);
                if (SResult.Tables.Contains("EKPOS"))
                {
                    foreach (DataRow row in SResult.Tables["EKPOS"].Rows)
                    {
                        row["EKPART"] =Helper.Convert8859P1ToGB2312(row["EKPART"].ToString());
                    }
                }
                SReturn.Merge(SResult); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }        
    }
}